package com.example.ordermealservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.commonutils.R;
import com.example.ordermealservice.entity.OrderBussiness;
import com.example.ordermealservice.service.OrderBussinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-06-11
 */
@RestController
@RequestMapping("/ordermealservice/orderbussiness")
public class OrderBussinessController {
    @Autowired
    private OrderBussinessService orderBussinessService;
    //后台模拟登录
    @PostMapping("/login")
    public R login(){
        return R.ok().data("token","admin");
    }
    //用户信息
    @GetMapping("/info")
    public R info(){
        return R.ok().data("roles","admin").data("name","admin").data("avatar",
                "wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
    }

    @GetMapping("/findAll")
    public R findAllTeacher(){
        List<OrderBussiness> list = orderBussinessService.list();
        return R.ok().data("list",list);
    }

    @PostMapping("register")
    public R register(@RequestBody OrderBussiness orderBussiness){
        String phone = orderBussiness.getPhone();
        LambdaQueryWrapper<OrderBussiness> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderBussiness::getPhone,phone);
        OrderBussiness one = orderBussinessService.getOne(queryWrapper);
        if (one != null){
            return R.error().message("该手机号已被注册");
        }
        orderBussinessService.save(orderBussiness);
        return R.ok().message("注册成功");
    }
}

